
package com.service.wmt.impl;

import com.dao.BuildingDao;
import com.dao.BuildingListDAO;
import com.entity.Building;
import com.entity.BuildingExample;
import com.entity.WmtBuildingList;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.wmt.BuildingService;
import com.util.gzp.AjaxResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class BuildingServiceImpl implements BuildingService {
    @Resource
    private BuildingDao buildingDao;

    @Resource
    private BuildingListDAO buildingListDAO;
    /**
     * 查询该楼盘所有楼栋
     * @return
     */
    @Override
    public List<Building> findAllBuilding(Integer hid) {
        BuildingExample buildingExample = new BuildingExample();
        BuildingExample.Criteria criteria = buildingExample.createCriteria();
        criteria.andHidEqualTo(hid);
        List<Building> buildingList = buildingDao.selectByExample(buildingExample);

        return buildingList;
    }

    @Override
    public AjaxResponse findAll(Integer hid, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<WmtBuildingList> list =buildingListDAO.findAll(hid);
        PageInfo<WmtBuildingList> pageInfo = new PageInfo<>(list);
        return AjaxResponse.success(pageInfo);
    }

    @Override
    public Integer insert(Building building) {
        return buildingDao.insert(building);
    }

    @Override
    public Building findByBuildingID(Integer buildingId) {
        return buildingDao.selectByPrimaryKey(buildingId);
    }

    @Override
    public Building findBuildingByBuildingIdAndHid(Integer buildingid, Integer hid) {
        BuildingExample example = new BuildingExample();
        BuildingExample.Criteria criteria = example.createCriteria();
        criteria.andBuildingidEqualTo(buildingid);
        criteria.andHidEqualTo(hid);
        return buildingDao.selectByExample(example).get(0);
    }

    @Override
    public Building findLastInsert() {
        System.out.println("BuildingServiceImpl.findLastInsert"+buildingListDAO.findLast());
        return buildingListDAO.findLast();
    }

}
